import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import axios from 'axios'
import API from '@/api'
import VueCookies from 'vue-cookies'
import ListToUtil from './until/tool.js'
Vue.prototype.$ListToUtil = ListToUtil
Vue.use(VueCookies)
// 导入时间插件momentjs
// import moment from 'moment'
 
// // 定义全局时间格式过滤器
// Vue.filter('dateFormat', function (daraStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
//   return moment(daraStr).format(pattern)
// })
Vue.prototype.$API = API
Vue.prototype.$axios = axios
Vue.config.productionTip = false
Vue.prototype.$host = process.env.VUE_APP_SERVER_HOST
Vue.use(ElementUI)
//Vue.http.options.xhr = { withCredentials: true } 
axios.defaults.withCredentials=true   //让ajax携带cookie
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8';
// axios.defaults.headers.post['Access-Control-Allow-Credentials'] = 'http://127.0.0.1:8080';
// 添加请求拦截器，在请求头中加token
axios.interceptors.request.use(
  config => {
    if (localStorage.getItem("message")) {
      config.headers.Authorization = localStorage.getItem("message");
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
